package com.study.manage.utils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

public class ManageUtils {

    public static String getRandomNum(int wei) {
        if (wei <= 0) {
            throw new IllegalArgumentException("wei must be positive");
        }
        StringBuilder ns = new StringBuilder("");
        for (int i = 0; i < wei; i++) {
            ns.append("9");
        }
        long num = Long.parseLong(ns.toString());
        Random randomGenerator = new Random();
        long name = Numbers.nextLong(randomGenerator, num);
        String nameCode =
                String.format(new StringBuilder("%0").append(wei).append("d").toString(), name);
        return nameCode;
    }


    public static Long getNumber(int wei) {
        if (wei <= 0) {
            throw new IllegalArgumentException("wei must be positive");
        }
        StringBuilder x = new StringBuilder("9");
        StringBuilder y = new StringBuilder("10");
        for (int i = 1; i < wei; i++) {
            x.append("0");
            y.append("0");
        }
        Long xx = Long.valueOf(x.toString());
        Random randomGenerator = new Random();
        long n = Numbers.nextLong(randomGenerator, xx);
        return Long.valueOf(y.toString()) - n;
    }


    public static String randomLetterStr(int wei) {
        if (wei <= 0) {
            throw new IllegalArgumentException("wei must be positive");
        }
        final char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
        StringBuilder ns = new StringBuilder("");
        Random randomGenerator = new Random();
        for (int i = 0; i < wei; i++) {
            ns.append(alphabet[randomGenerator.nextInt(alphabet.length - 1)]);
        }
        return ns.toString();
    }


    public static String getShowPrice(List<String> charges) {

        StringBuilder chargeSb = new StringBuilder("");
        try {
            List<Float> cs = new ArrayList<>();
            for (String c : charges) {
                cs.add(Float.valueOf(c));
            }
            if (cs.isEmpty()) {
                chargeSb.append("--");
            } else if (cs.size() == 1) {
                if (cs.get(0).equals(0f)) {
                    chargeSb.append("免费");
                } else {
                    chargeSb.append("￥").append(Collections.max(cs));
                }
            } else if (cs.size() > 1) {
                chargeSb.append("￥").append(Collections.min(cs));
                chargeSb.append("~").append(Collections.max(cs));
            }
        } catch (NumberFormatException e) {
        }
        return chargeSb.toString();
    }

}
